package cn.humaohua.study.yanmo_design_pattern.ch20.v2;

import java.util.concurrent.TimeUnit;

/**
 * clear thread is running
 * clear over, sleep 1 second
 * true
 * false
 * true
 * view count...
 * 人员列表,查看  引用计数=3
 * 薪资数据,查看  引用计数=1
 * clear thread is running
 * clear over, sleep 1 second
 * view count...
 * 人员列表,查看  引用计数=3
 * 薪资数据,查看  引用计数=1
 * clear thread is running
 * view count...
 * 人员列表,查看  引用计数=3
 * clear over, sleep 1 second
 * 薪资数据,查看  引用计数=1
 * clear thread is running
 * clear over, sleep 1 second
 * view count...
 * 人员列表,查看  引用计数=3
 * 薪资数据,查看  引用计数=1
 * clear thread is running
 * clear over, sleep 1 second
 * view count...
 * 人员列表,查看  引用计数=3
 * 薪资数据,查看  引用计数=1
 * clear thread is running
 * clear over, sleep 1 second
 * view count...
 * 人员列表,查看  引用计数=3
 * 薪资数据,查看  引用计数=1
 * clear thread is running
 * view count...
 * remove cache key=人员列表,查看
 * remove cache key=薪资数据,修改
 * remove cache key=薪资数据,查看
 * clear over, sleep 1 second
 * 人员列表,查看  引用计数=0
 * 薪资数据,查看  引用计数=0
 */
public class Client {
    public static void main(String[] args) {
        SecurityMgr securityMgr = SecurityMgr.getInstance();
        boolean hasPermit = securityMgr.hasPermit("张三", "人员列表", "查看");
        System.out.println(hasPermit);
        hasPermit = securityMgr.hasPermit("张三", "薪资数据", "查看");
        System.out.println(hasPermit);

        hasPermit = securityMgr.hasPermit("李四", "薪资数据", "查看");
        System.out.println(hasPermit);

//        securityMgr.print();


        while(true){
            try {
                System.out.println("view count...");
                System.out.println("人员列表,查看  引用计数="+FlyweightFactory.getInstance().getUseTimes("人员列表,查看"));
                System.out.println("薪资数据,查看  引用计数="+FlyweightFactory.getInstance().getUseTimes("薪资数据,查看"));
                TimeUnit.SECONDS.sleep(1);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
